// **************************************************************
// Com ++ Framework by the C++ World
// Please report defects: mailto:compp@cplusplusworld.com
// Please visit: http://www.cplusplusworld.com/socketlibrary.html
// **************************************************************

#include <iostream>
#include <string>
#include <cstdlib>
#include "ComPlusPlus/ComPlusPlus"
 
int main (int argc, char *argv [] ) {

if ( argc != 3 ) {
  std::cout << "Usage " << argv[0] << " SocketClntFN SocketServerFN\n";
  return 1;
} 

 std::string str,FNC =  argv [1];
 std::string FNS =  argv [2];
 std::string string2besent= "Hello World";
 std::string string2bereceived;
 char c [ 100 ] ;
 int ret;

try {
  // -> Comment 1
  compp::SocketUnix Client (FNC, compp::DATAGRAM);	
  // -> Comment 2
  compp::SocketUnix Server (FNS, compp::DATAGRAM);	

  ret = Client.Sendto ( "Hello", 5, FNS );
  std::cout << "sent " << ret << "bytes\n";

  memset ( c, 0, sizeof ( c ) ) ;
  ret = Server.Recvfrom ( c, 3, 0, FNS );
  std::cout << "received " << c << " " << ret << "\n";

  ret = Client.Sendto ( "World", 5, FNS );
  std::cout << "sent " << ret << "bytes\n";

  memset ( c, 0, sizeof ( c ) ) ;
  ret = Server.Recvfrom ( c, 2, 0, FNS );
  std::cout << "received " << c << " " << ret << "\n";

} catch ( syspp::ComException e ) {
	std::cout <<  "Exception " << e.what() << "\n" ;	
}
 return 0;	
}
